# import cv2
# import numpy as np
#
# img = cv2.imread("d:\\test\\test.jpg",1)
# img_gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
# ret, thresh = cv2.threshold(img_gray, 127, 255, 0)
# contours, hierarchy, _ = cv2.findContours(thresh, 2, 1)
# cnt = contours[0]
#
# hull = cv2.convexHull(cnt, returnPoints=False)
# defects = cv2.convexityDefects(cnt, hull)
#
# for i in range(defects.shape[0]):
#     s, e, f, d = defects[i, 0]
#     start = tuple(cnt[s][0])
#     end = tuple(cnt[e][0])
#     far = tuple(cnt[f][0])
#     cv2.line(img, start, end, [0, 255, 0], 2)
#     cv2.circle(img, far, 5, [0, 0, 255], -1)
#
# cv2.imshow('img', img)
# cv2.waitKey(0)
# cv2.destroyAllWindows()

# # 1.先找到轮廓
# img = cv2.imread('d:\\test\\start.jpg', 0)
# _, thresh = cv2.threshold(img, 0, 255, cv2.THRESH_BINARY + cv2.THRESH_OTSU)
# image, contours, hierarchy = cv2.findContours(thresh, 3, 2)
# cnt = contours[0]
#
# # 2.寻找凸包，得到凸包的角点
# hull = cv2.convexHull(cnt)
#
# # 3.绘制凸包
# image = cv2.cvtColor(image, cv2.COLOR_GRAY2BGR)
# cv2.polylines(image, [hull], True, (0, 255, 0), 2)
# cv2.imshow('img', image)
# cv2.waitKey(0)
# cv2.destroyAllWindows()


# import cv2
# import numpy as np
#
# img = cv2.imread('d:\\test\\test.jpg')
# img_gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
# ret, thresh = cv2.threshold(img_gray, 127, 255, 0)
# contours = cv2.findContours(thresh, 2, 1)
# hierarchy = cv2.findContours(thresh, 2, 1)
# cnt = contours[0]
#
# hull = cv2.convexHull(cnt, returnPoints=False)
# defects = cv2.convexityDefects(cnt, hull)
#
# for i in range(defects.shape[0]):
#     s, e, f, d = defects[i, 0]
#     start = tuple(cnt[s][0])
#     end = tuple(cnt[e][0])
#     far = tuple(cnt[f][0])
#     cv2.line(img, start, end, [0, 255, 0], 2)
#     cv2.circle(img, far, 5, [0, 0, 255], -1)
# while (1):
#     cv2.imshow('img', img)
#     if cv2.waitKey(1) == ord('q'):
#         break
# cv2.destroyAllWindows()
